<!--信息管理详情-->
<script lang="ts">
  export default {
    name: '代码生成详情',
  }
</script>
<script lang="ts" setup>
  import { DtlParamManager, EDIT_TYPE_ENUM, collapseExpandIcon, t } from '@/utils/common'
  import { provide } from 'vue'
  import { DpmObs, DpmPipe } from './util'
  import { taxExemptionApi } from '@/api/tesApi'
  import { onMounted, ref } from 'vue'
  import { ActionBar, PanelHeader, CommonList } from '@longnows/ui'
  import { Collapse, CollapsePanel } from 'ant-design-vue'
  import { useBodyActions, useBodyForms, useBodyInfoForms, useBodyTables, useHeaderActions, useHeaderForm, useListOperation } from './hooks/'

  const PAGE_CODE = "<%= pageCode %>"
  const { editType = EDIT_TYPE_ENUM.ADD, uid = '' } = window.Longnows.router.currentRoute.value.query
  const dpm = new DtlParamManager<DpmPipe, DpmObs>(uid, editType)
  provide('dpm', dpm)

  const { headerForm, headerMethods } = useHeaderForm(dpm)
  const { headerActionFun, headerActionConfig } = useHeaderActions(dpm)
  const showHeaderInfo = ref<boolean>(true)
  const showProjectInfo = ref<boolean>(true)
  let CollapseActiveKey = ref<string[]>(['header', 'projectInfo'])

  let getDetail = async () => {
    if (dpm.getUid()) {
      const res = await taxExemptionApi.getDetail(dpm.getUid())
      if (res.code === 0) {
        const data = res.data
        headerMethods?.setFieldsValue(data)
      }
    }
  }

  const commonListRef = ref<InstanceType<typeof CommonList> | null>(null)
  const { openBodyInfoModal, BodyInfoModal } = useBodyInfoForms(dpm)
  const { headerBodyActionFun, afterGetActions } = useBodyActions(dpm, commonListRef, openBodyInfoModal)
  const { getOptions, afterGetSchemas } = useBodyForms(dpm)
  const { afterGetColumns } = useBodyTables()
  const { addOperationColumn } = useListOperation(dpm, openBodyInfoModal)
  const getList = (searchReq, pageReq) => {
    console.log('🚀 ~ getList ~ searchReq, pageReq:', searchReq, pageReq)
    return Promise.resolve({
      code: 0,
      data: [{}],
      total: 0,
    })
  }

  let init = () => {}
  dpm.observer.on('getDetail', getDetail)
  onMounted(() => {
    if (dpm.getCpt('notAdd').value) {
      getDetail()
    } else {
      init()
    }
  })
</script>

<template>
  <div class="flex-content-wrapper">
    <div class="flex-content">
      <div class="header-container">
        <Collapse ghost v-model:activeKey="CollapseActiveKey" :expandIcon="collapseExpandIcon" expandIconPosition="right" v-show="showHeaderInfo">
          <CollapsePanel key="header" :forceRender="true" :showArrow="false" class="header-panel">
            <template #header>
              <PanelHeader class="block-title header-title" :header="t('表头')" style="font-size: 16px; font-weight: 700" panelKey="header" :activeKey="CollapseActiveKey"></PanelHeader>
            </template>
            <ActionBar class="header-actions" :actionConfig="headerActionConfig" :actionFun="headerActionFun" :onlyDisabledShow="true" />
            <div class="container-padding">
              <Collapse v-model:activeKey="CollapseActiveKey" :expandIcon="collapseExpandIcon" expandIconPosition="right" class="compact-coll" v-show="showProjectInfo">
                <CollapsePanel key="projectInfo" :header="t('项目信息')" class="form-panel" :forceRender="true">
                  <headerForm></headerForm>
                </CollapsePanel>
              </Collapse>
            </div>
          </CollapsePanel>
        </Collapse>
        <div class="container-block body-container" style="border: none">
          <div class="block-title">{{ t('表体明细') }}</div>
          <div class="container-padding body-list">
            <div class="body-list-wraper">
              <CommonList
                ref="commonListRef"
                rowKey="uid"
                :pageCode="PAGE_CODE"
                :actionFun="headerBodyActionFun"
                :afterGetActions="afterGetActions"
                :afterGetColumns="afterGetColumns"
                :afterGetSchemas="afterGetSchemas"
                :getList="getList"
                :getOptions="getOptions"
                :addOperationColumn="addOperationColumn"
              ></CommonList>
            </div>
          </div>
        </div>
      </div>
    </div>
    <BodyInfoModal></BodyInfoModal>
  </div>
</template>

<style scoped lang="less">
  @import './detail.less';
</style>
